import * as types from '../mutation-types'

const state = {
  class:'',
  pindex:'',
  isShowShade:false,
  pageSet: []
}

const actions = {
  showShade({ commit, state }, playload){
    commit(types.SHOW_SHADE,playload)
  },
  addParent ({ commit, state }, playload) {
    commit(types.ADD_PARENT_NODE,playload)
  },
  addChild({ commit, state },playload){
    commit(types.ADD_CHILD_NODE,playload)
  }
}

const mutations = {
  [types.SHOW_SHADE] (state, playload) {
    state.isShowShade = playload.state;
    state.class = playload.class;
    state.pindex = playload.pindex;
  },
  [types.ADD_PARENT_NODE] (state, playload) {
    state.pageSet.push({
      pageName:playload.nodeValue,
      children:[]
    }) 
  },
  [types.ADD_CHILD_NODE] (state, playload) {
    state.pageSet[state.pindex].children.push({
      pageName:playload.nodeValue
    })
  }
}

export default {
  state,
  actions,
  mutations
}